

${"<"}#include "/base/common/head.html"/>
    
    <table id="dg"></table>
    <div id="tb" style="padding:2px 5px;">
        <div class="wrap_search">
			<#list queryFields as item>
				<#if item.fieldType == "java.lang.String">
					<#if item.addType == "S12" || item.addType == "S22">
			            	<span class="search_item">
				            	<span class="item_text">${item.showName}：</span>
				            	<span class="item_obj">
				            		<input class="easyui-combobox" type="text" name="${item.fieldName}" id="${item.fieldName}" value=""  addClear
               							data-options="valueField:'${item.parameter}',textField:'${item.parameter}',url:'${'$'}{basePath}${item.addSelectUrl}'"></input>
				            	</span>    
				            </span>
					<#elseif item.addType == "S11" || item.addType == "S21">
			            	<span class="search_item">
				            	<span class="item_text">${item.showName}：</span>
				            	<span class="item_obj">
				            		<input class="easyui-combobox" type="text" name="${item.fieldName}" id="${item.fieldName}" value=""  addClear
               							data-options="valueField:'name',textField:'name',data: ${item.parameterData}"></input>
				            	</span>    
				            </span>
	           		<#else>
		           			<span class="search_item">
						         <span class="item_text">${item.showName}：</span>
						         <span class="item_obj">
						         	<input class="easyui-textbox" addClear type="text" name="${item.fieldName}" id="${item.fieldName}" value="" data-options=""></input>
						         </span>    
						    </span>
	           		</#if>
				
				<#elseif item.fieldType == "java.util.Date">
		        			<span class="search_item search_between">
				                <span class="item_text">${item.showName}：</span>
				                <span class="item_obj">
				                    <input class="easyui-datebox" addClear name="${item.fieldName}_start" id="${item.fieldName}_start" 
				                    	data-options="editable:false,width:'110px'" value=""/> ~ <input class="easyui-datebox" 
				                    	addClear name="${item.fieldName}_end" id="${item.fieldName}_end" data-options="editable:false,width:'110px'" value=""/>
				                </span>
				            </span>
				<#elseif item.otherBo>
							<span class="search_item">
				            	<span class="item_text">${item.showName}：</span>
				            	<span class="item_obj">
				            		<input class="easyui-combobox" addClear type="text" name="${item.fieldName}Id" id="${item.fieldName}Id" value="" 
               							data-options="valueField:'id',textField:'${item.parameter}',url:'${'$'}{basePath}${item.addSelectUrl}',editable:false"></input>
				            	</span>    
				            </span>
				</#if>
          	</#list>	            
		        		
        </div>
        <div style="text-align: left; margin:6px;">
        	<!--  
            -->
            <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add()">增加</a>
            <a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="update()">编辑</a>
            <a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove" plain="true" onclick="del()">删除</a>
            <a href="javascript:void(0)" class="easyui-linkbutton detailBtn" iconCls="glyphicon-map-marker" plain="true" onclick="detail()">详情</a>
            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-export" plain="true" onclick="exportExcel('all')">导出</a>
            
			<#list listFields as item>
				<#if item.excelType>
            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-export" plain="true" onclick="exportExcel('${item.fieldName}')">分${item.showName}导出</a>
				</#if>
          	</#list>	
          	
            <div id="searchBtnWrap" style="float:right; padding-right:40px;">
                <a href="javascript:void(0)" class="easyui-linkbutton color1" iconCls="glyphicon-search" onclick="zcurdSearch()">搜索</a>
                <a href="javascript:void(0)" class="easyui-linkbutton color2" iconCls="glyphicon-repeat" onclick="flushPage()">重置</a>
            </div>
            
        </div>
    </div>
    
<script type="text/javascript">

//数据表格初始化参数
var dgOptions = {
        rownumbers:true, //显示行号
    	fit:true, //自适应父容器
    	border:false, //是否显示面板边框。
    	url:'listData',  //数据请求URL
    	method:'post', //请求方式
    	toolbar:'#tb', //工具栏
    	pageSize: 20, //每页数量
    	pagination:true, //显示分页
    	//fitColumns:true, //自动调整各列宽度。当为true时，各列的宽度值只是一个比例。
    	striped:true, //是否显示斑马线
    	multiSort:false, //是否允许多列排序
		sortName:'${curd.defaultOrderFieldName}', //初始排序字段
		sortOrder:'${curd.defaultOrderType}', //初始排序方式
    	singleSelect: false, //是否单选
		ctrlSelect : true, //启用多选时，允许使用Ctrl键+鼠标进行多选
		showFooter : true, //是否显示行脚
        queryParams: zcurdGetParam(), //请求参数
        onDblClickRow:function(index, row){dbClickShow(row.id);}, //双击行事件
        columns: [[
		         {field:'id', checkbox:true}
	           	<#list listFields as item>
	           	 	,{field:'${item.fieldName}', title: '${item.showName!item.fieldName}', width:${item.listWidth}, align:'${item.listAlign}' <#if item.listSortable >,sortable:true</#if> <#if item.listFormatter?? >,formatter:${item.listFormatter}</#if> }
	          	</#list>	 
	           	 
	           ]],
	      loadFilter: function(data) {
	        	   if(data.result && data.result == 'fail') {	//失败时，错误消息提示
	        		   showWarnMsg(data.msg);
	        		   return {};
	        	   }else {
	        		   return data;
	        	   }
	           }           
	};



var datagrid = $("#dg"); //数据表格

$(function() {
	datagrid.datagrid(dgOptions); //绘制数据表格
	autoAddClear(); //为各组件自动填加‘清除’功能（组件需要增加 addClear属性 ）
});

//查询
function zcurdSearch() {
	var param = zcurdGetParam();
	datagrid.datagrid("load", param)
}

//获取查询参数
function zcurdGetParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param[$(item).attr("name")] = $(item).val();	
		}
	});
	//console.log(param);
	return param;
}

var initPara = zcurdGetParam(); //初始化参数，主要目的是保存一些隐藏条件

//增加
function add() {
	top.window.subPage.loadCurrDatagrid = function() { //设置成功后的回调方法
		datagrid.datagrid("load");
	}
	top.openWindow("增加", getCurrUrl("addPage") + "?" + $.param(initPara), {size: '${curd.windowSize_add}'});
}

//修改
function update() {
	var rowsSel = datagrid.datagrid("getChecked");
	if(rowsSel.length != 1) {
		showWarnMsg("请选【一条】数据！");
		return;
	}
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		datagrid.datagrid("reload");
	}
	top.openWindow("编辑", getCurrUrl("updatePage") + "?id=" + id, {size: '${curd.windowSize_update}'});
}

//详情
function detail() {
	var rowsSel = datagrid.datagrid("getChecked");
	if(rowsSel.length != 1) {
		showWarnMsg("请选【一条】数据！");
		return;
	}
	var id = rowsSel[0].id;
	dbClickShow(id);
}

//双击打开查看
function dbClickShow(id) {
	top.openWindow_view("详情", getCurrUrl("detailPage") + "?id=" + id, {size: '${curd.windowSize_detail}'});
}

//删除
function del() {
	var ids = [];
	$.each(datagrid.datagrid("getChecked"), function(i, item) {
		ids.push(item.id);
	});
	if(ids.length < 1) {
		showWarnMsg("请选择数据！");
		return;
	}
	confirmMsg("确认删除?", function() {
		$.post(getCurrUrl("delete"), {ids: ids.join(",")}, function(data) {
			
			if("01" == data.code){//成功
				datagrid.datagrid("reload");
				showMsg(data.msg); //显示消息
			}else if("04" == data.code){//失败
				showErrorMsg(data.msg); //显示错误消息
			}
			
		});
	});
}

//导出Excel
function exportExcel(type) {
	var option = datagrid.datagrid("options");
	var param = option.queryParams;
	param.sort = option.sortName;
	param.order = option.sortOrder;
	param.type = type;
	window.location.href = "exportExcel?" + $.param(param);
}


/**
 * 格式化函数
 */
 
<#list listFields as item>
	<#if item.otherBo>	
	
//格式化：${item.showName!item.fieldName} 
function format${item.fieldName}(value)
{
	if(value == null)
	{
		return "";
	}
	return value.${item.parameter};
};	

	<#elseif item.fieldType == "java.lang.Boolean">
	
//格式化：${item.showName!item.fieldName} 
function format${item.fieldName}(value)
{
	if(value == null)
	{
		return "";
	}
	if(value)
	{
		return "${item.parameter}";
	}
	return "${item.falseShow}";
};
	
	</#if>
</#list>


</script>

${"<"}#include "/base/common/dialogWindow.html"/>
${"<"}#include "/base/common/foot.html"/>
